import { Observer } from 'mobx-vue'
import { Component, Vue } from 'vue-property-decorator'
import { getDepartmentList } from 'src/utils/axios'
import departmentAdd from 'src/views/system/department/components/department-add/department-add.vue' 
require('./department.scss')
@Observer
@Component({
    components:{
        departmentAdd
    }
})
export default class ZtCommunity extends Vue {
    name:any = '';
    //添加部门弹出层
    isAdd: boolean = false
    // 分页
    page: number = 1
    pageNo: number = 1
    pageSize: number = 10
    count: number = 0//总条数
    tableData:any = [];
    queryForm:any = {
        name: '',
        contact: '',
        telephone: '',
    }
    tableColums:any= [
        {
            title: '#ID',
            key: 'id'
        },
        {
            title: '部门名称',
            key: 'name'
        },
        {
            title: '联系人',
            key: 'contact'
        },
        {
            title: '联系方式',
            key: 'telephone'
        },
        {
            title: '联系地址',
            key: 'address'
        },
        {
            align: 'center',
            title: '操作',
            slot: 'operation'
        }
    ]
    
    mounted() {
       let vm:any = this;
       vm.getList(1);
    }
    　　      // 添加部门
    digAdd() {
      let vm = this
      vm.isAdd = false
      vm.getList(vm.pageNo)
  }
    async getList(page){
        let vm:any = this;
        let filter:any = {};
        for (const key in vm.queryForm) {
            if (vm.queryForm[key]) {
                filter[key] = vm.queryForm[key];
            }
        }
        let params:any = {
            "filter": filter,
            "range": [(page-1)*10, page * 10],
            "sort": []
        }
        
        let out:any = await getDepartmentList(params);
        if (!out.status) {
            // if (!out.data.list.length && page > 1) {
            //     vm.getList(page)
            //     return
            // }
            vm.page = page
            vm.count = out.data.total;
            vm.tableData = out.data.list
            console.log('vm.tableData',vm.tableData)
        }else {
            vm.$Message.error(await vm.$api.xerror(out.status));
        }
    }
     //改变页码
     async changePage(index) {
        this.getList(index)
    }

}
